package com.weijianhuawen.wjblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.weijianhuawen.wjblog.common.config.InsertBatchMapper;
import com.weijianhuawen.wjblog.common.domain.dos.ArticleTagRelDo;
import com.weijianhuawen.wjblog.common.domain.dos.TagDo;

import java.util.List;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-10-24 16:42
 */
public interface ArticleTagRelMapper extends InsertBatchMapper<ArticleTagRelDo> {
    // 根据文章id删除其对应标签的关联
    default int deleteTagsOfArticleByArticleId(Long articleId) {
        return delete(Wrappers.<ArticleTagRelDo>lambdaQuery()
                .eq(ArticleTagRelDo::getArticleId, articleId));
    }

    // 根据文章id查询对应的tag关联
    default List<ArticleTagRelDo> selectByArticleId(Long articleId) {
        return selectList(Wrappers.<ArticleTagRelDo>lambdaQuery()
                .eq(ArticleTagRelDo::getArticleId, articleId));
    }

    // 根据标签id查询关联记录
    default ArticleTagRelDo selectOneByTagId(Long tagId) {
        return selectOne(Wrappers.<ArticleTagRelDo>lambdaQuery()
                .eq(ArticleTagRelDo::getTagId, tagId)
                .last("LIMIT 1"));
    }
    //通过标签id查询所有关联记录
    default List<ArticleTagRelDo> selectListByTagId(Long tagId) {
        return selectList(Wrappers.<ArticleTagRelDo>lambdaQuery()
                .eq(ArticleTagRelDo::getTagId, tagId));
    }

    default List<ArticleTagRelDo> selectByArticleIds(List<Long> articleIds) {
        return selectList(Wrappers.<ArticleTagRelDo>lambdaQuery()
                .in(ArticleTagRelDo::getArticleId, articleIds));
    }
}
